﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KVB.Common;

namespace Customer_Profile.Admin
{
    public partial class AddCode : System.Web.UI.Page
    {
        DataSet ds = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                string strSourceID =Request.QueryString["id"].ToString();

                string id = strSourceID.Split(',')[0].ToString();
                string strType = strSourceID.Split(',')[1].ToString();

                if (strType.Equals("E"))  //选择了最后一级
                {
                    Comm.ViewMsgGoUrl("CodeManage.aspx", "It Must Less Then Two Layers");
                }
                else
                {
                    try
                    {
                        CodeTypeDao codetypedao = new CodeTypeDao();
                        ds = codetypedao.GetModel(id);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteDefaultLog("AddCodePage_Load", ex.ToString());
                    }
                    if (!Page.IsPostBack)
                    {
                        drpType.DataSource = ds.Tables[0];
                        drpType.DataTextField = "CodeTypeName";
                        drpType.DataValueField = "id";
                        drpType.DataBind();
                        drpType.Items.FindByValue(id).Selected = true;
                    }
                }
            }
            else
            {
                Comm.ViewMsgGoUrl("CodeManage.aspx", "Categories Not Exist");
            }            
        }

        protected void ibtnAdd_ServerClick(object sender, EventArgs e)
        {
            CodeDao codedao = new CodeDao();
            codedao.Add(drpType.SelectedValue.Trim(), txtName.Value.Trim(), txtValue.Value.Trim(), txtRemark.Value.Trim(), txtOrderid.Value.Trim(), drpUsed.SelectedValue.Trim());
            Comm.ViewMsgGoUrl("CodeManage.aspx", "Success");
        }

        protected void ibtnBack_ServerClick(object sender, EventArgs e)
        {
            Response.Redirect("CodeManage.aspx");
        }
    }
}
